package com.blog.domain;

import com.blog.web.WebUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;

public class Favorites extends POJO {

	private static final long serialVersionUID = 9151959746035648118L;

	// �ֶ�
	private String fname;
	private String flink;
	private String fdescription;
	private String time;
	private String author;
	private int ops;

	@Override
	protected String getTable() {
		return "favorites";
	}

	@Override
	protected Map<String, Object> listFields() {
		Map<String,Object> fields = super.listFields();
		fields.remove("shortName");
		fields.remove("shortDescription");
		fields.remove("encodedUrl");
		return fields;
	}

	public String getShortName(){
		if(fname != null){
			fname = WebUtils.regule(fname);
			if( fname.length() > 25 ){
				return fname.substring(0,25) + "...";
			}
		}
		return fname;
	}

	public String getShortDescription(){
		if( fdescription != null ){
			fdescription = WebUtils.regule(fdescription);
			if( fdescription.length() > 200 ){
				return fdescription.substring(0,200) + "...";
			}
		}
		return fdescription;
	}

	public String getEncodedUrl() throws UnsupportedEncodingException {
		if( flink != null ){
			return URLEncoder.encode(flink,"UTF-8");
		}
		return flink;
	}

	public String getFname() {
		return fname;
	}

	public void setFname(String fname) {
		this.fname = fname;
	}

	public String getFlink() {
		return flink;
	}

	public void setFlink(String flink) {
		this.flink = flink;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getFdescription() {
		return fdescription;
	}

	public void setFdescription(String fdescription) {
		this.fdescription = fdescription;
	}

	public int getOps() {
		return ops;
	}

	public void setOps(int ops) {
		this.ops = ops;
	}

}
